package com.icss.dao.redis;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@Component
public class RedisStringDao {
	@Autowired
	private JedisPool pool;
	private Jedis jd;
	
	public int set(String key,String value){
		int r=0;
		try{
			jd=pool.getResource();
			jd.set(key, value);
			jd.close();
			r=1;
		}catch(Exception ex){
			ex.printStackTrace();
		}
		return r;
	}
	public String get(String key){
		jd=pool.getResource();
		String r=jd.get(key);
		jd.close();
		return r;
	}
	public Set<String> getKeys(String pattern){
		Set<String> valSet=new HashSet<String>();
		jd=pool.getResource();
		Set<String> r = jd.keys(pattern);
		for (String key : r) {
			String v=jd.get(key);
			valSet.add(v);
		}
		jd.close();
		return valSet;
	}
}
